package com.esri.android.map.popup;

import android.app.Activity;
import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.esri.android.map.popup.ArcGISAttributesAdapter;
import com.esri.android.map.popup.ArcGISPopupStyle;
import com.esri.core.map.popup.PopupInfo;
import java.util.EnumSet;
import java.util.Set;

/* loaded from: classes.dex */
public class ArcGISReadOnlyAttributesAdapter extends ArcGISAttributesAdapter {
    private WebView a;

    @Override // com.esri.android.map.popup.ArcGISAttributesAdapter
    public void refresh() {
    }

    public ArcGISReadOnlyAttributesAdapter(Context context, Popup popup) {
        super(context, popup);
        final PopupInfo popupInfo = this.mPopup.a;
        if (popupInfo == null || popupInfo.getDescription() == null || popupInfo.getDescription().equalsIgnoreCase("null") || !(context instanceof Activity)) {
            return;
        }
        ((Activity) context).runOnUiThread(new Runnable() { // from class: com.esri.android.map.popup.ArcGISReadOnlyAttributesAdapter.1
            @Override // java.lang.Runnable
            public void run() {
                ArcGISReadOnlyAttributesAdapter arcGISReadOnlyAttributesAdapter = ArcGISReadOnlyAttributesAdapter.this;
                ArcGISReadOnlyAttributesAdapter arcGISReadOnlyAttributesAdapter2 = ArcGISReadOnlyAttributesAdapter.this;
                arcGISReadOnlyAttributesAdapter.a = new DescriptionView(arcGISReadOnlyAttributesAdapter2.mContext, popupInfo);
            }
        });
    }

    @Override // com.esri.android.map.popup.ArcGISAttributesAdapter, android.widget.Adapter
    public int getCount() {
        if (this.a != null) {
            return 1;
        }
        return super.getCount();
    }

    @Override // android.widget.Adapter
    public View getView(int i, View view, final ViewGroup viewGroup) {
        ArcGISAttributesAdapter.FIELD_TYPE determineFieldType;
        WebView webView = this.a;
        if (webView != null) {
            webView.setOnTouchListener(new View.OnTouchListener() { // from class: com.esri.android.map.popup.ArcGISReadOnlyAttributesAdapter.2
                @Override // android.view.View.OnTouchListener
                public boolean onTouch(View view2, MotionEvent motionEvent) {
                    viewGroup.onTouchEvent(MotionEvent.obtain(motionEvent));
                    if (motionEvent.getAction() != 2) {
                        return ArcGISReadOnlyAttributesAdapter.this.a.onTouchEvent(motionEvent);
                    }
                    return false;
                }
            });
            return this.a;
        }
        ArcGISAttributesAdapter.AttributeInfo attributeInfo = getAttributeInfo(i);
        if ((attributeInfo.fieldInfo == null || attributeInfo.fieldInfo.isVisible()) && (determineFieldType = determineFieldType(attributeInfo)) != ArcGISAttributesAdapter.FIELD_TYPE.UNSUPPORTED) {
            ArcGISAttributesAdapter.LayoutResource layoutResource = getLayoutResource(determineFieldType);
            ViewGroup createLayout = layoutResource.createLayout();
            ((TextView) createLayout.findViewById(layoutResource.mLabelViewId)).setText(attributeInfo.fieldInfo == null ? getAttributeName(i) : attributeInfo.fieldInfo.getLabel());
            ((TextView) createLayout.findViewById(layoutResource.mValueViewId)).setText(this.mValueFormat.formatValue(this.mFeatureType, attributeInfo.value, attributeInfo.fieldInfo));
            return createLayout;
        }
        return null;
    }

    /* loaded from: classes.dex */
    public class DescriptionView extends WebView implements ArcGISPopupStyle.IPopupStylable {
        String a;

        public DescriptionView(Context context, PopupInfo popupInfo) {
            super(context);
            this.a = popupInfo == null ? "" : ArcGISReadOnlyAttributesAdapter.this.mValueFormat.a(ArcGISReadOnlyAttributesAdapter.this.mFeatureType, popupInfo.getDescription());
            ArcGISPopupStyle arcGISPopupStyle = (ArcGISPopupStyle) ArcGISReadOnlyAttributesAdapter.this.mPopup.getLayout().getStyle();
            arcGISPopupStyle.registerStylable(this);
            applyStyle(arcGISPopupStyle, ArcGISPopupStyle.STYLE_ELEMENT.POPUP_BACKGROUND);
            applyStyle(arcGISPopupStyle, ArcGISPopupStyle.STYLE_ELEMENT.FIELD_VALUE);
        }

        @Override // com.esri.android.map.popup.ArcGISPopupStyle.IPopupStylable
        public Set<ArcGISPopupStyle.STYLE_ELEMENT> getRegisteredStyle() {
            return EnumSet.of(ArcGISPopupStyle.STYLE_ELEMENT.POPUP_BACKGROUND, ArcGISPopupStyle.STYLE_ELEMENT.FIELD_VALUE);
        }

        @Override // com.esri.android.map.popup.ArcGISPopupStyle.IPopupStylable
        public void applyStyle(ArcGISPopupStyle arcGISPopupStyle, ArcGISPopupStyle.STYLE_ELEMENT style_element) {
            String str;
            if (arcGISPopupStyle == null) {
                return;
            }
            if (ArcGISPopupStyle.STYLE_ELEMENT.POPUP_BACKGROUND.equals(style_element)) {
                setBackgroundColor(arcGISPopupStyle.getPopupBackgroundColor());
            } else if (!ArcGISPopupStyle.STYLE_ELEMENT.FIELD_VALUE.equals(style_element) || (str = this.a) == null || "".equals(str)) {
            } else {
                String format = String.format("#%06X", Integer.valueOf(arcGISPopupStyle.getFieldValueColor() & 16777215));
                loadDataWithBaseURL(null, "<font color='" + format + "'>" + this.a + "</font>", "text/html", "utf-8", null);
            }
        }
    }

    /* loaded from: classes.dex */
    public static class FieldValueView extends TextView implements ArcGISPopupStyle.IPopupStylable {
        public FieldValueView(Context context, String str, ArcGISPopupStyle arcGISPopupStyle) {
            super(context);
            setPadding(0, PopupUtil.convertDpInPixels(context, 13), PopupUtil.convertDpInPixels(context, 10), PopupUtil.convertDpInPixels(context, 5));
            applyStyle(arcGISPopupStyle, ArcGISPopupStyle.STYLE_ELEMENT.FIELD_VALUE);
            setText(str);
            setAutoLinkMask(1);
            setGravity(16);
            arcGISPopupStyle.registerStylable(this);
        }

        @Override // com.esri.android.map.popup.ArcGISPopupStyle.IPopupStylable
        public Set<ArcGISPopupStyle.STYLE_ELEMENT> getRegisteredStyle() {
            return EnumSet.of(ArcGISPopupStyle.STYLE_ELEMENT.FIELD_VALUE);
        }

        @Override // com.esri.android.map.popup.ArcGISPopupStyle.IPopupStylable
        public void applyStyle(ArcGISPopupStyle arcGISPopupStyle, ArcGISPopupStyle.STYLE_ELEMENT style_element) {
            if (arcGISPopupStyle == null) {
                return;
            }
            setTextSize(1, arcGISPopupStyle.getFieldValueFontSize());
            setTypeface(arcGISPopupStyle.getFieldValueFontType(), arcGISPopupStyle.getFieldValueFontStyle());
            setTextColor(arcGISPopupStyle.getFieldValueColor());
        }
    }

    @Override // com.esri.android.map.popup.ArcGISAttributesAdapter
    protected ViewGroup createDefaultLayout(ArcGISAttributesAdapter.FIELD_TYPE field_type) {
        View separatorView;
        if (this.a != null) {
            return null;
        }
        LinearLayout linearLayout = new LinearLayout(this.mContext);
        linearLayout.setOrientation(1);
        ArcGISPopupStyle arcGISPopupStyle = (ArcGISPopupStyle) this.mPopup.getLayout().getStyle();
        ArcGISAttributesAdapter.FieldLabelView fieldLabelView = new ArcGISAttributesAdapter.FieldLabelView(this.mContext, "", arcGISPopupStyle);
        fieldLabelView.setId(1);
        linearLayout.addView(fieldLabelView);
        if (arcGISPopupStyle.getCustomFieldSeparator() != null) {
            separatorView = arcGISPopupStyle.getCustomFieldSeparator();
        } else {
            separatorView = new ArcGISAttributesAdapter.SeparatorView(this.mContext, arcGISPopupStyle);
        }
        linearLayout.addView(separatorView);
        FieldValueView fieldValueView = new FieldValueView(this.mContext, "", arcGISPopupStyle);
        fieldValueView.setId(2);
        linearLayout.addView(fieldValueView);
        return linearLayout;
    }
}
